<?php
/*
+--------------------------------------------------------------------------
|   AffiliStore 2
|   ========================================
|   Web: http://www.affilistore.com
|   Email: admin (at) affilistore (dot) com
|	License Type: AffiliStore 2 is NOT open source software and limitations apply 
|   Licence Info: Visit AffiliStore website and click on 'Licence'
+--------------------------------------------------------------------------
*/
set_include_path(PATH_SEPARATOR . dirname(realpath(__FILE__)) . '/' . 'classes/' . PATH_SEPARATOR . dirname(realpath(__FILE__)) . '/' . get_include_path() );
require_once('includes/connect.php');
require_once('includes/functions.php');
include_once 'includes/models/Click.php';

mysql_select_db($database, $databaseConnect);


// get skin value
$getConfigSkin = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'adSkinURL'");
$configSkin = mysql_fetch_assoc($getConfigSkin);
// get install directory
$getInstallDir = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'installDir'");
$installDir = mysql_fetch_assoc($getInstallDir);

// get the category listings
$sql = sprintf("SELECT * FROM affiliSt_products1 WHERE prodDB = %d AND dbProdID = %s",
				quote_smart($_GET['proddb']),
				quote_smart($_GET['l']));
$getLinks = mysql_query($sql, $databaseConnect) or die(mysql_error());
$merchantLink = mysql_fetch_assoc($getLinks);

$link = $merchantLink['prodLink'];

// add 1 to popular products count
$addToProd = $merchantLink['prodPopularity'] + 1;
$thisProdID = $merchantLink['dbProdID'];

$botlist = array(
"Teoma",
"alexa",
"froogle",
"inktomi",
"looksmart",
"URL_Spider_SQL",
"Firefly",
"NationalDirectory",
"Ask Jeeves",
"TECNOSEEK",
"InfoSeek",
"WebFindBot",
"girafabot",
"crawler",
"www.galaxy.com",
"Googlebot",
"Scooter",
"Slurp",
"appie",
"FAST",
"WebBug",
"Spade",
"ZyBorg",
"rabaz");

$totalbots = count($botlist);
$botcounter = 0;
for ($i=0; $i<$totalbots; $i++) {
	if(ereg($botlist[$i], $HTTP_USER_AGENT)) {
	
	$botcounter = $botcounter+1;
	
	}
}

if ($botcounter == 0) {
$sql = sprintf("UPDATE affiliSt_products1 SET prodPopularity = %s WHERE prodDB = %d AND dbProdID = %s",
				quote_smart($addToProd),
				quote_smart($_GET['proddb']),
				quote_smart($thisProdID));
$dbUpdate = mysql_query($sql, $databaseConnect) or die(mysql_error());
}

// un-comment below if you prefer to use php header redirect:
//header("Location: $link");


if ($merchantLink['merchant'] != '') {
$theMerchant = $merchantLink['merchant'];
} else {
$theMerchant = 'this shop';
}

/**
 * Add one click to database, table affiliSt_clicks
 */

$click = new Click();
$newClick['prodID'] = $merchantLink['prodID'];
$newClick['clickTime'] = date('Y-m-d H:i:s');
$newClick['accId'] = $merchantLink['accId'];
$newClick['clickIp'] = $_SERVER['REMOTE_ADDR'];
$click->add($newClick);

/**
 * Finish add click
 */
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Loading the product from <?php echo $theMerchant ?>...</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="robots" content="noindex, nofollow, nocache, noarchive">
<meta http-equiv="refresh" content="1;url=<?php echo $link; ?>">
<style type="text/css">
body { font: 130% arial, helvetica, sans-serif; background: #fff; text-align: center; }
p{ margin: 50px 0; color: #c0c0c0;}
p span { border-top: 1px solid #c0c0c0; padding: 3px; font-size: 65%; color: #777; }
</style>
</head>

<body>

<p><img src="<?php echo $installDir['value'].'skins/'.$configSkin['value'].'/styleImages/progress.gif'; ?>" width="31" height="31" alt="In progress"></p>
<p>Thank you for using our website. Please visit us again.</p>
<p>The product from <?php echo $theMerchant ?> will load shortly.</p>
<p><span>Been waiting a while? <a id="redirect" href="<?php echo $link; ?>" rel="external nofollow">Go directly to <?php echo $theMerchant ?></a></span></p>

</body>
</html>